#include "drv_dma.h"
#include "stdio.h"
void drv_dma_init(uint32_t *src,uint32_t *drc,uint32_t size)
{
	DMA_InitTypeDef DMA_InitStruct;
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
	
	DMA_InitStruct.DMA_BufferSize = size;//需要搬运数据的数量
	DMA_InitStruct.DMA_Channel = DMA_Channel_0;//DMA通道，可任意选择
	DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToMemory;//从内存到内存
	DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;
	DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)drc;//目标地址
	DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;//单次突发
	DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;//全字传输
	DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;//地址自增
	DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;//正常模式，不使用循环模式
	
	DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)src;//数据源的地址
	DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//单次突发
	DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;//全字传输
	DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Enable;//源地址自增
	DMA_InitStruct.DMA_Priority = DMA_Priority_High;//DMA的优先级
	DMA_Init(DMA2_Stream0, &DMA_InitStruct);
	DMA_Cmd(DMA2_Stream0, ENABLE);
}
extern uint32_t dma_src[];
extern uint32_t dma_drc[];
void drv_dmadata_compare(void)
{
	uint8_t i=0;
	for(i=0;i<10;i++)
	{
		if(dma_src[i] != dma_drc[i])
		{
			printf("dma_data is error!\r\n");
			return;
		}
	}
	printf("dma_data is ok!\r\n");
}

